<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>卖家中心</title>
    <!--获取屏幕宽度，根据屏幕宽度进行自适应-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--引入Bootstrap-->
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!--自定义工具-->
    <script src="js/HttpUtil.js"></script>
    <!--导入vue 包-->
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>


    <style>
        a:hover {
            color: #cc3333;
            text-decoration: none;
        }

        a {
            color: black;
            cursor: pointer;
        }
    </style>
</head>

<body>

<div class="container-fluid" style="margin-top: 1%">
    <!-- 头信息 -->
    <header>
        <div class="col-xs-offset-1">
            <img src="../view-api/images/vip.logo.png">
        </div>
        <hr>
        <div class="row" style="background-color: #A4D3EE">
            <div class="col-xs-2 col-lg-offset-1">
                <h4>GitBug 商城订单管理</h4>
            </div>
        </div>
    </header>


    <div class="row">
        <div class="col-xs-1 col-lg-offset-1" style="background-color:#F7F7F7; height: 800px; position: absolute">
            <h5 style="padding:50% 0 10% 20%"><a href="home_admin.html">概况</a></h5>
            <h5 style="padding:10% 0 10% 20%"><a href="goods-manage.html">商品管理</a></h5>
            <h5 style="padding:10% 0 10% 20%"><a href="orderItems_admin.html">订单管理</a></h5>
            <h5 style="padding:10% 0 10% 20%"><a href="data_analyse.html">数据中心</a></h5>
        </div>
        <div class="col-lg-offset-2 " style="margin-top: 1%">
            <h4>个人中心&nbsp>&nbsp订单管理</h4>
            <hr>
        </div>

        <!-- 订单列表展示  -->
        <div class=" col-md-8 col-lg-offset-2" id="order_vue">
            下单时间：
            <input type="date" id="datetime1">-
            <input type="date" id="datetime2">
            <input type="button" value="搜索" @click="searchByDate()">

            <table class="table table-striped table-bordered table-hover" style="margin-top: 1%">
                <thead>
                <tr class="success">
                    <th>订单ID</th>
                    <th>状态</th>
                    <th>金额</th>
                    <th>商品数量</th>
                    <th>买家姓名</th>
                    <th>下单时间</th>
                    <th>发货时间</th>
                    <th>取消时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="order in orderList">
                    <td>{{order.id}}</td>
                    <td>{{order.status | showStatus}}</td>
                    <td>{{order.orderPrice  |showPrice}}</td>
                    <td>{{order.quantity}}</td>
                    <td>{{order.userName}}</td>
                    <td>{{order.createDate | formatDate}}</td>
                    <td>{{order.deliveryDate|formatDate}}</td>
                    <td>{{order.cancelDate|formatDate }}</td>
                    <td class="inputButton">
                        <input type="button" class="btn btn-primary" :id="order.id" @click="viewDetail(order.id)"
                               value="产看详细">
                        <input type="button" class="btn btn-success " :id="order.deliveryDate"
                               @click="sendOrder(order.id)" v-if="order.deliveryDate===null && order.cancelDate===null "
                               value="发货">
                        <input type="button" class="btn btn-warning " :id="order.cancelDate" @click="cancelOrder(order.id)"
                               v-if="order.cancelDate===null" value="取消">
                    </td>
                </tr>

                <tr id="goodsDetail"  >
                    <td colspan="9">
                        <table>
                            <tr  v-for="goodsDetail in goodsDetailList" style="text-align: center" >
                                <div :class="goodsDetail.number"></div>
                                <td class="col-md-2"><img :src="goodsDetail.imgUrl" style="height: 100px"></td>
                                <td class="col-md-3">{{goodsDetail.goodsName}}</td>
                                <td class="col-md-1">{{goodsDetail.goodsNumber}}个</td>
                                <td class="col-md-1">{{goodsDetail.price|showPrice}}</td>
                            </tr>
                        </table>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>


<!-- 页脚信息 -->
<div class="container-fluid" style="background-color: ghostwhite; margin-top: 5%; ">
    <div class="row" style="margin-top: 2%;margin-bottom: 5%">
        <div class="col-xs-1 col-xs-offset-2">
            <p style="">视频中心</p>
            <a>
                <div style="padding-top: 10%">新闻发布会</div>
            </a>
            <a>
                <div style="padding-top: 5%">发展历程</div>
            </a>
            <a>
                <div style="padding-top: 5%">直播</div>
            </a>
            <a>
                <div style="padding-top: 5%">员工视频</div>
            </a>
        </div>
        <div class="col-xs-1 ">
            <p style="">发现</p>
            <a>
                <div style="padding-top: 10%">成功故事</div>
            </a>
            <a>
                <div style="padding-top: 5%">公司年报</div>
            </a>
            <a>
                <div style="padding-top: 5%">管理层信息</div>
            </a>
            <a>
                <div style="padding-top: 5%">媒体图库</div>
            </a>
        </div>
        <div class="col-xs-1 ">
            <p style="">关注我们</p>
            <a>
                <div style="padding-top: 10%">新浪微博</div>
            </a>
            <a>
                <div style="padding-top: 5%">微信公众号</div>
            </a>
            <a>
                <div style="padding-top: 5%">优酷视频</div>
            </a>
            <a>
                <div style="padding-top: 5%">哔哩哔哩</div>
            </a>
        </div>
        <div class="col-xs-1 ">
            <a href="http://localhost:80/v iews/view-api/home2.html">商城主页</a>
        </div>
    </div>
</div>
</body>
</html>

<script type="text/javascript">


    const vue = new Vue({
        el: '#order_vue',
        data: {
            orderList: "",
            goodsDetailList: "",

        },

        filters: {
            //价格
            showPrice(price) {
                return '￥' + price.toFixed(2)
            },
            //订单状态
            showStatus(status) {
                switch (status) {
                    case 1:
                        return "待支付"
                    case 2:
                        return "待发货"
                    case 3:
                        return "待收货"
                    case 4:
                        return "待评价"
                    case 5:
                        return "已完成"
                    case 6:
                        return "已取消"
                    case 7:
                        return "已退款"
                    case 8:
                        return "申请取消中"
                    case 9:
                        return "申请退款中"
                }
            },
            //时间格式化
            formatDate(value) {
                if (value != null) {
                    let date = new Date(value);
                    let y = date.getFullYear();
                    let MM = date.getMonth() + 1;
                    MM = MM < 10 ? ('0' + MM) : MM;
                    let d = date.getDate();
                    d = d < 10 ? ('0' + d) : d;
                    let h = date.getHours();
                    h = h < 10 ? ('0' + h) : h;
                    let m = date.getMinutes();
                    m = m < 10 ? ('0' + m) : m;
                    let s = date.getSeconds();
                    s = s < 10 ? ('0' + s) : s;
                    return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
                } else {
                    return null
                }
            }

            //
        },

        methods: {
            //根据日期获取订单，默认未全部获取
            searchByDate: function () {
                let url = "order/selectOrder"
                let beforeDate = document.getElementById("datetime1").value;
                let afterDate = document.getElementById("datetime2").value;
                let params = {beforeDate: beforeDate, afterDate: afterDate};
                let thisObject = this;
                postWithParams(url, params, function (data) {
                    thisObject.orderList = data;
                    thisObject.goodsDetailList = "";
                })
            },

            //点击发货事件
            sendOrder: function (id) {
                let url = "order/sendOrder";
                let thisObject = this;
                let params = {id: id}
                postWithParams(url, params, function () {
                    thisObject.searchByDate()
                });
            },

            //点击取消事件
            cancelOrder: function (id) {
                let url = "order/cancelOrder";
                let thisObject = this;
                let params = {id: id};
                postWithParams(url, params, function () {
                    thisObject.searchByDate()
                })
            },

            //点击查看详细事件
            viewDetail: function (id) {
                let url = "order/orderDetail";
                let thisObject = this;
                let params = {id: id};
                postWithParams(url, params, function (data) {
                    console.log("进入订单详细");
                    thisObject.goodsDetailList = data;
                    thisObject.isShow=!thisObject.isShow

                    let parent = $("#" + id).parent().parent();
                    let goodsDetail = $("#goodsDetail");
                    parent.after(goodsDetail);
                })
            },
        },

        mounted: function () {
            //页面加载完成，并且vue对象加载完成之后调用
            this.searchByDate()
        },
    });

</script>
